package com.youth.orderservice.controller;


import com.youth.commonutils.R;
import com.youth.orderservice.entity.OrderVo.OrderQuery;
import com.youth.orderservice.entity.TOrder;
import com.youth.orderservice.service.TOrderService;
import com.youth.orderservice.service.TPayLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author huangqicai
 * @since 2023-04-06
 */
@Api("订单模块")
@RestController
@RequestMapping("/orderservice/Torder")
//@CrossOrigin
public class TOrderController {

    @Autowired
    private TOrderService tOrderService;

    @Autowired
    private TPayLogService tPayLogService;

    @ApiOperation(value = "根据课程id和用户id去创建订单")
    @GetMapping("/createOrder/{courseId}/{userId}")
    public R createOrder(@PathVariable(value = "courseId") String courseId,
                         @PathVariable(value = "userId") String userId){
        System.out.println("");
        return tOrderService.createOrder(courseId,userId);

    }


    @ApiOperation(value = "根据订单id获取订单详细信息")
    @GetMapping("/getOrderById/{orderId}")
    public R getOrderById(@PathVariable(value = "orderId") String orderId){
        return tOrderService.getOrderById(orderId);
    }


    @ApiOperation(value = "分页条件查询订单信息")
    @PostMapping("/getPageList/{current}/{limit}")
    public R getPageList(@PathVariable(value = "current") long current,
                         @PathVariable(value = "limit") long limit,
                         @RequestBody OrderQuery orderQuery){
        return tOrderService.getPageList(current,limit,orderQuery);
    }


    @ApiOperation(value = "根据订单id删除订单信息")
    @GetMapping("/deleteOrder/{orderId}")
    public R deleteOrder(@PathVariable(value = "orderId") String orderId){
        return tOrderService.deleteOrder(orderId);
    }


    @ApiOperation(value = "根据订单id和订单实体类更新订单信息")
    @PostMapping("/updateOrder/{orderId}")
    public R updateOrder(@PathVariable(value = "orderId") String orderId,
                         @RequestBody TOrder tOrder){
        return tOrderService.updateOrder(orderId,tOrder);
    }

}

